Date.prototype.format = function(format) {
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
	// millisecond
	}
	if (/(y+)/.test(format))
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	for ( var k in o)
		if (new RegExp("(" + k + ")").test(format))
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
	return format;
}

//时间格式化
function dateFormatter(timem){
	return new Date(timem).format('yyyy-MM-dd');
}

//时间格式化
function dateFormatter_yyyyMMddHHmmss(time){
	if(time==null || time == ""){
		return "/";
	}
	return new Date(time).format('yyyy-MM-dd HH:mm:ss');
}

//时间格式化
function showTime(dateLong) { 
	  var now = new Date(dateLong); 
	  var nowTime = now.toLocaleString(); 
	  var date = nowTime.substring(0,10);//截取日期 
	  var time = nowTime.substring(10,20); //截取时间 
	  var week = now.getDay(); //星期 
	  var hour = now.getHours(); //小时 
	  //判断星期几 
	  var weeks = ["日","一","二","三","四","五","六"]; 
	  var getWeek = "星期" + weeks[week]; 
	  var sc; 
	  //判断是AM or PM 
	  if(hour >= 0 && hour < 5){ 
	   sc = '凌晨'; 
	  } 
	  else if(hour > 5 && hour <= 7){ 
	   sc = '早上'; 
	  } 
	  else if(hour > 7 && hour <= 11){ 
	   sc = '上午'; 
	  } 
	  else if(hour > 11 && hour <= 13){ 
	   sc = '中午'; 
	  } 
	  else if(hour> 13 && hour <= 18){ 
	   sc = '下午'; 
	  } 
	  else if(hour > 18 && hour <= 23){ 
	   sc = '晚上'; 
	  } 
	  var dateStr = date+" " + getWeek +" "+"  "+time;
	  return dateStr;
	} 

//在tab里面新增一个tab
function addSubPage(title,url){    
    var jq = top.jQuery;    
    if (jq("#tabs").tabs('exists', title)){    
        jq("#tabs").tabs('select', title);    
    } else {  
          var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';     
           jq("#tabs").tabs('add',{    
                              title:title,    
                              content:content,    
                              closable:true,
                              iconCls:'icon-application_form_edit'
                            });    
     }    
}


//扩展datagrid editor 支持datetimebox,原本只支持datebox
$.extend($.fn.datagrid.defaults.editors, {    
  datetimebox: {    
      init: function(container, options){    
          var editor = $('<input />').appendTo(container);
          options.editable = false;
          editor.datetimebox(options)
          return editor;    
      },    
      getValue: function(target){    
          return $(target).datetimebox('getValue');    
      },    
      setValue: function(target, value){    
          $(target).datetimebox('setValue',value);   
      },    
      resize: function(target, width){    
      	 $(target).datetimebox('resize',width);
      },
      destroy: function(target){
      	$(target).datetimebox('destroy');
      }
  }    
}); 
